package com.cserver.pro.controller;


import com.cserver.pro.service.SysUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息表(SysUser)表控制层
 *
 * @author makejava
 * @since 2020-02-22 09:45:23
 */
@RestController
@RequestMapping("sysUser")
public class SysUserController {
    /**
     * 服务对象
     */
    @Autowired
    private SysUserService sysUserService;

    /**
     * 通过主键查询单条数据
     *
     * @param
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    @RequiresPermissions("sys:user:get")
    public String selectOne( String userId) {
    return this.sysUserService.queryById(new Long("1")).toString();
    }

    @RequiresPermissions("sys:user:more")
    @GetMapping("/selectMore")
    public String selectAll( String userId) {
        sysUserService.queryAllByLimit(0,10);

        return "获取多个数据成功";
    }

    @PostMapping("/login")
    public String login(@RequestParam(value = "username", required = false)String username,
                        @RequestParam(value = "password", required = false)String password){
        UsernamePasswordToken token = new UsernamePasswordToken(username, password);
        Subject subject=SecurityUtils.getSubject();
        try
        {
            subject.login(token);
            return "成功";
        }catch (Exception e){
            e.getStackTrace();
            return "失败";
        }
     //   return "未知";
    }

    @GetMapping(value = "/unLogin")
    @ResponseBody
    public String toLogin(int code){
//        System.out.println("ddddddd");
        return code==1?"未登陆":"未授权";
    }

}